package com.tanhua.server.interceptor;

import com.tanhua.model.domain.User;

/**
 * @auther ll
 * @date 2022/3/24  20:38
 * 工具类
 */
public class UserHolder {

    private  static ThreadLocal<User> tl = new ThreadLocal<>();

    //将用户对象，存入Threadlocal
    public static void  set(User user){
        tl.set(user);
    }

    //从当前线程，获取用户对象
    public static User get(){
        return tl.get();
    }

    //从当前线程，获取用户对象手机号码
    public static String getMobile(){
        return tl.get().getMobile();
    }

    //清空
    public static  void  remove(){
        tl.remove();
    }

    //从当前线程，获取用户对象的id
    public static Long getUserId() {
        return tl.get().getId();
    }
}
